/*
 * Decompiled with CFR 0.150.
 * 
 * Could not load the following classes:
 *  cn.hutool.core.date.DateUtil
 *  cn.hutool.core.util.ObjectUtil
 *  com.alibaba.fastjson.JSON
 *  de.felixroske.jfxsupport.FXMLController
 *  javafx.application.Platform
 *  javafx.event.EventHandler
 *  javafx.fxml.FXML
 *  javafx.fxml.Initializable
 *  javafx.scene.control.Alert
 *  javafx.scene.control.Alert$AlertType
 *  javafx.scene.control.DatePicker
 *  javafx.scene.input.KeyCode
 *  javafx.scene.input.KeyEvent
 *  javafx.scene.layout.AnchorPane
 *  javafx.stage.Modality
 *  javafx.util.StringConverter
 *  org.springframework.beans.factory.annotation.Autowired
 */
package com.gys.controller.replenish;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSON;
import com.gys.GysApplication;
import com.gys.common.business.ReplenishUtil;
import com.gys.common.data.HttpJson;
import com.gys.common.util.CacheUtil;
import com.gys.common.util.CommonUtil;
import com.gys.common.util.ConstUtil;
import com.gys.controller.BaseController;
import com.gys.controller.index.IndexController;
import com.gys.controller.replenish.AddReplenishController;
import com.gys.controller.replenish.ReplenishController;
import com.gys.data.replenish.GetReplenishInData;
import com.gys.view.replenish.AddView;
import de.felixroske.jfxsupport.FXMLController;
import java.net.URL;
import java.time.LocalDate;
import java.util.Calendar;
import java.util.Date;
import java.util.ResourceBundle;
import javafx.application.Platform;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Alert;
import javafx.scene.control.DatePicker;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent;
import javafx.scene.layout.AnchorPane;
import javafx.stage.Modality;
import javafx.util.StringConverter;
import org.springframework.beans.factory.annotation.Autowired;

@FXMLController
public class AddTipReplenishController
extends BaseController
implements Initializable {
    private final int pageSize = ConstUtil.DEFAULT_PAGESIZE;
    private final int defaultPageCount = ConstUtil.DEFAULT_PAGECOUNT;
    @FXML
    private AnchorPane pane;
    @FXML
    private DatePicker replenishDate;
    @Autowired
    private ReplenishController acceptController;
    @Autowired
    private IndexController indexController;
    @Autowired
    private AddReplenishController addReplenishController;

    public void initialize(URL location, ResourceBundle resources) {
        StringConverter converter = CommonUtil.dataPickerFormat("yyyyMMdd");
        this.replenishDate.setConverter(converter);
    }

    @Override
    public void init() {
        if (ObjectUtil.isEmpty(this.pane)) {
            return;
        }
        this.replenishDate.setValue(null);
        this.indexController.scrollContentPane.setOnKeyReleased((EventHandler)new EventHandler<KeyEvent>(){

            public void handle(KeyEvent event) {
                if (event.getCode() == KeyCode.ENTER) {
                    AddTipReplenishController.this.openAdd();
                    return;
                }
                if (event.getCode() == KeyCode.ESCAPE) {
                    AddTipReplenishController.this.closeWindows();
                    return;
                }
            }
        });
    }

    @FXML
    private void openAdd() {
        boolean flag;
        Calendar calendar = Calendar.getInstance();
        calendar.set(6, calendar.get(6) + 7);
        Long maxDate = calendar.getTime().getTime();
        Long dateTime = DateUtil.parse((String)((LocalDate)this.replenishDate.getValue()).toString(), (String)"yyyy-MM-dd").getTime();
        Long now = DateUtil.parse((String)DateUtil.format((Date)new Date(), (String)"yyyyMMdd"), (String)"yyyyMMdd").getTime();
        if (dateTime < now) {
            Alert alert = this.createAlert(Alert.AlertType.INFORMATION, "\u63d0\u793a\u4fe1\u606f", "\u8f93\u5165\u65e5\u671f\u5fc5\u987b\u5927\u4e8e\u7b49\u4e8e\u5f53\u524d\u65e5\u671f");
            alert.showAndWait();
            return;
        }
        if (dateTime > maxDate) {
            Alert alert = this.createAlert(Alert.AlertType.INFORMATION, "\u63d0\u793a\u4fe1\u606f", "\u8f93\u5165\u65e5\u671f\u5fc5\u987b\u5c0f\u4e8e\u5f53\u524d\u65e5\u671f\u540e7\u5929");
            alert.showAndWait();
            return;
        }
        GetReplenishInData inData = new GetReplenishInData();
        inData.setGsrhDate(DateUtil.format((Date)DateUtil.parse((String)((LocalDate)this.replenishDate.getValue()).toString()), (String)"yyyyMMdd"));
        HttpJson rsp = ReplenishUtil.isRepeat(inData);
        if (rsp.isSuccess() && (flag = ((Boolean)JSON.parseObject((String)rsp.getMsg(), Boolean.TYPE)).booleanValue())) {
            Alert alert = this.createAlert(Alert.AlertType.INFORMATION, "\u63d0\u793a\u4fe1\u606f", "\u4e00\u4e2a\u81ea\u7136\u65e5\u5185\u53ea\u80fd\u8fdb\u884c\u4e00\u6b21\u6b63\u5e38\u8865\u8d27");
            alert.showAndWait();
            return;
        }
        CacheUtil.put("replenishDate", DateUtil.format((Date)DateUtil.parse((String)((LocalDate)this.replenishDate.getValue()).toString()), (String)"yyyyMMdd"));
        this.pane.getScene().getWindow().hide();
        Platform.runLater((Runnable)new Runnable(){

            @Override
            public void run() {
                AddTipReplenishController.this.init();
                AddTipReplenishController.this.addReplenishController.init();
                GysApplication.showView(AddView.class, (Modality)Modality.APPLICATION_MODAL);
            }
        });
    }

    @FXML
    private void closeWindows() {
        this.init();
        this.pane.getScene().getWindow().hide();
    }

    public int getPageSize() {
        return this.pageSize;
    }

    public int getDefaultPageCount() {
        return this.defaultPageCount;
    }

    public AnchorPane getPane() {
        return this.pane;
    }

    public DatePicker getReplenishDate() {
        return this.replenishDate;
    }

    public ReplenishController getAcceptController() {
        return this.acceptController;
    }

    public IndexController getIndexController() {
        return this.indexController;
    }

    public AddReplenishController getAddReplenishController() {
        return this.addReplenishController;
    }

    public void setPane(AnchorPane pane) {
        this.pane = pane;
    }

    public void setReplenishDate(DatePicker replenishDate) {
        this.replenishDate = replenishDate;
    }

    public void setAcceptController(ReplenishController acceptController) {
        this.acceptController = acceptController;
    }

    public void setIndexController(IndexController indexController) {
        this.indexController = indexController;
    }

    public void setAddReplenishController(AddReplenishController addReplenishController) {
        this.addReplenishController = addReplenishController;
    }

    public boolean equals(Object o) {
        if (o == this) {
            return true;
        }
        if (!(o instanceof AddTipReplenishController)) {
            return false;
        }
        AddTipReplenishController other = (AddTipReplenishController)o;
        if (!other.canEqual(this)) {
            return false;
        }
        if (this.getPageSize() != other.getPageSize()) {
            return false;
        }
        if (this.getDefaultPageCount() != other.getDefaultPageCount()) {
            return false;
        }
        AnchorPane this$pane = this.getPane();
        AnchorPane other$pane = other.getPane();
        if (this$pane == null ? other$pane != null : !this$pane.equals(other$pane)) {
            return false;
        }
        DatePicker this$replenishDate = this.getReplenishDate();
        DatePicker other$replenishDate = other.getReplenishDate();
        if (this$replenishDate == null ? other$replenishDate != null : !this$replenishDate.equals(other$replenishDate)) {
            return false;
        }
        ReplenishController this$acceptController = this.getAcceptController();
        ReplenishController other$acceptController = other.getAcceptController();
        if (this$acceptController == null ? other$acceptController != null : !(this$acceptController).equals(other$acceptController)) {
            return false;
        }
        IndexController this$indexController = this.getIndexController();
        IndexController other$indexController = other.getIndexController();
        if (this$indexController == null ? other$indexController != null : !(this$indexController).equals(other$indexController)) {
            return false;
        }
        AddReplenishController this$addReplenishController = this.getAddReplenishController();
        AddReplenishController other$addReplenishController = other.getAddReplenishController();
        return !(this$addReplenishController == null ? other$addReplenishController != null : !(this$addReplenishController).equals(other$addReplenishController));
    }

    protected boolean canEqual(Object other) {
        return other instanceof AddTipReplenishController;
    }

    public int hashCode() {
        int PRIME = 59;
        int result = 1;
        result = result * 59 + this.getPageSize();
        result = result * 59 + this.getDefaultPageCount();
        AnchorPane $pane = this.getPane();
        result = result * 59 + ($pane == null ? 43 : $pane.hashCode());
        DatePicker $replenishDate = this.getReplenishDate();
        result = result * 59 + ($replenishDate == null ? 43 : $replenishDate.hashCode());
        ReplenishController $acceptController = this.getAcceptController();
        result = result * 59 + ($acceptController == null ? 43 : ($acceptController).hashCode());
        IndexController $indexController = this.getIndexController();
        result = result * 59 + ($indexController == null ? 43 : ($indexController).hashCode());
        AddReplenishController $addReplenishController = this.getAddReplenishController();
        result = result * 59 + ($addReplenishController == null ? 43 : ($addReplenishController).hashCode());
        return result;
    }

    public String toString() {
        return "AddTipReplenishController(pageSize=" + this.getPageSize() + ", defaultPageCount=" + this.getDefaultPageCount() + ", pane=" + this.getPane() + ", replenishDate=" + this.getReplenishDate() + ", acceptController=" + this.getAcceptController() + ", indexController=" + this.getIndexController() + ", addReplenishController=" + this.getAddReplenishController() + ")";
    }
}

